﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Threading.Tasks;
using WMS.Seven.IQiData.Dto;
using WMS.Seven.IQiData;
using WMS.Seven.Qi;
using WMS.Seven.Qi.Dto;

namespace WMS.Seven.Web.Controllers.QiData
{
    public class QiDataController : Controller
    {
        private readonly QiDataService _qiDataService;
        private readonly LossReportingService _lossReportingService;
        private readonly ProductService _productService;
        public QiDataController(QiDataService qiDataService, LossReportingService lossReportingService, ProductService productService)
        {
            _qiDataService = qiDataService;
            _lossReportingService = lossReportingService;
            _productService = productService;
        }
        [HttpGet]
        public async Task<JsonResult> GetSale(string SalesOrderCode = "", int page = 1, int limit = 3)
        {
            var a= await _qiDataService.GetSale(SalesOrderCode, page, limit);
            return Json(a);
        }


        /// <summary>
        /// 采购退货单查询
        /// </summary>
        /// <param name="SalesOrderCode"></param>
        /// <param name="ProcurementCode"></param>
        /// <param name="ProductName"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSales(string SalesOrderCode = "", string ProcurementCode = "", string ProductName = "", int page = 1, int limit = 10)
        {
            var a = await _qiDataService.GetSales(SalesOrderCode, ProcurementCode, ProductName, page, limit);
            return Json(a);
        }
        /// <summary>
        /// 采购退货显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult SalesIndex()
        {
            return View();
        }

        /// <summary>
        /// 获取损耗报告数据
        /// </summary>
        /// <param name="lossReportingDTO"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetLossReportingData(RequestLossReportingDTO lossReportingDTO)
        {
            var result = await _lossReportingService.GetLossReportingData(lossReportingDTO);
            return Json(result);
        }
        /// <summary>
        /// 创建损耗报告
        /// </summary>
        /// <param name="createLossReportingDTO"></param>
        /// <returns></returns>
        public async Task<bool> CreateLossReporting(CreateLossReportingDTO createLossReportingDTO)
        {
            var result = await _lossReportingService.CreateLossReporting(createLossReportingDTO);
            return true;
        }
        /// <summary>
        /// 更新损耗报告
        /// </summary>
        /// <param name="updateLossReportingDTO"></param>
        /// <returns></returns>
        public async Task<bool> UpdateLossReporting(UpdateLossReportingDTO updateLossReportingDTO)
        {
            var lossReporting = await _lossReportingService.UpdateLossReporting(updateLossReportingDTO);
            return true;
        }

        /// <summary>
        /// 删除损耗报告
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteLossReporting(int id)
        {
            var lossReporting = await _lossReportingService.DeleteLossReporting(id);
            return true;
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> UpdateStutes(int id)
        {
            var result = await _lossReportingService.UpdateStutes(id);
            return result;
        }

        /// <summary>
        /// 报损管理
        /// </summary>
        /// <returns></returns>
        public IActionResult LossReportingManagement()
        {
            return View();
        }
        /// <summary>
        /// 添加报损管理
        /// </summary>
        /// <returns></returns>
        public IActionResult AddLossReportingManagement()
        {
            return View();
        }
        /// <summary>
        /// 修改报损管理
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdLossReportingManagement()
        {
            return View();
        }



        /// <summary>
        /// 获取产品
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<object> GetProduct(RequestProductDTO productDTO)
        {
            var result = await _productService.GetProduct(productDTO);
            return result;
        }

        public IActionResult Product()
        {
            return View();
        }




    }
}
